package com.sunxd.spinnertest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class MainActivity extends AppCompatActivity {

    private Spinner mSpinner;
    private ArrayAdapter<String> mSpinnerAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mSpinner = findViewById(R.id.spinner);
        mSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item); // 指定未展开的Spinner样式
        mSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // 指定展开的Spinner的列表项样式
        mSpinnerAdapter.add("搜索所有汽车车型");
        mSpinnerAdapter.add("小型轿车");
        mSpinnerAdapter.add("SUV");
        mSpinnerAdapter.add("MPV");
        mSpinner.setAdapter(mSpinnerAdapter);
        mSpinner.setSelection(0); // 默认选择第0项
    }
}